package kr.hkit.androidcomplete01.ch12;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListItemSelect extends Activity {
	String[] arGeneral = {"김유신", "이순신", "강감찬", "을지문덕"};
	ArrayAdapter<String> Adapter;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listviewtest);

		
		Adapter = new ArrayAdapter<String>(this, 
				android.R.layout.simple_list_item_1, arGeneral);

		ListView list = (ListView)findViewById(R.id.list);
		list.setAdapter(Adapter);
		list.setOnItemClickListener(mItemClickListener);
	}
	
	AdapterView.OnItemClickListener mItemClickListener = 
			new AdapterView.OnItemClickListener() {
		public void onItemClick(AdapterView<?> parent, View view, 
				int position, long id) {
			StringBuilder sb = new StringBuilder();
			sb.append(parent.getCount() + "개");
			sb.append(view.getId()+"view id\t");
			sb.append("position = " + position+"id = " + id);
			sb.append(Adapter.getItem(position));
			Toast.makeText(ListItemSelect.this, sb.toString(), Toast.LENGTH_LONG).show();
			
		}
	};
}